﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AutoMapper关系映射例子.Models;
using AutoMapper;

namespace AutoMapper关系映射例子.Controllers
{
    public class HomeController : Controller
    {
        //Mapper.Initialize(x => { x.AddProfile<SourceProfile>(); });
        public IActionResult Index()
        {
            //Mapper.Initialize(x => { x.AddProfile<SourceProfile>(); });
           

            Person p = new Person();
            p.Id = 1;
            p.Name = "杨建椿";
            p.IsDeleted = false;

            var dto= Common.ToDTO(p);


            Student s = new Student();
            s.Id = 2;
            s.Name = "yjc";
            s.Desc = "我是帅哥";
            s.IsDeleted = true;

            var dto2 = Common.ToDTO<Student,StudentDTO>(s,new StudentDTO());

            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
